﻿
using LPP.Entity.Addresses;
using LPP.EntityFrameworkCore;
using LPP.Repository.AddressRepository;
using Microsoft.EntityFrameworkCore;  // 确保添加此命名空间

public class AddressRepository : IAddressRepository
{
    private readonly SqlDbContext _context;

    public AddressRepository(SqlDbContext context)
    {
        _context = context;
    }

    public async Task AddAddressAsync(Address address)
    {
        _context.Add(address);
        await _context.SaveChangesAsync();
    }

    public async Task<List<Address>> GetAddressesByUserIdAsync(int userId)
    {
        return await _context.Addresses
                             .Where(a => a.UserID == userId)
                             .ToListAsync();  // 这里的 ToListAsync 是 Entity Framework Core 提供的异步扩展方法
    }
}

